home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
INFO
/
PCCDEMO.ZIP
/
COMP1.EXE
/
WATSPEED.PRS
< prev
next >
Wrap
Text File
|
1993-12-20
|
7KB
|
155 lines
ûçÇô ÆÅääâ? ╬╠╬╠╬╠╬╠╬╠╧╧╡
îα±Γ â⌠σε⌠±.
ôτΣ≥Σ πα√≥, ÷Φ≤τ ≤τΣ ΦφσΦφΦ≤Σδ√ ⌡α±√Φφµ ∩ε÷Σ± εσ ≤επα√'≥ Γε∞∩⌠≤Σ±≥, Φ≤ Φ≥
≥ε∞Σ≤Φ∞Σ≥ α ΓταδδΣφµΣ ≤ε πΣ≥Φµφ α ⌠≥Σ± Φφ≤Σ±σαΓΣ ≤τα≤ ÷Φδδ ßΣ ≥∩ΣΣπΦδ√
Γεφ≥Φ≥≤Σφ≤ σ±ε∞ Γε∞∩⌠≤Σ± ≤ε Γε∞∩⌠≤Σ±. The fastest micro-processors will
execute the same instructions more than 150 times faster than the slowest
chips available, thus adding slightly to the challenge of producing software
that will perform consistently from one machine to the other.
ôτΣ ∞Σ≤τεπ ±Σ≤αΦφΣπ Φφ⌡εδ⌡Σ≥ ≤τΣ ⌠≥Σ εσ α "≥∩ΣΣπ ΦφπΣ≈",
that is proportional to the speed of the microprocessor
executing the code below.
The higher the number, the faster the chip is. This
number is simply obtained by counting the number of
iterations of a particular "representative code" routine
during a fixed time interval obtained by the system's
real-time clock. The "representative code" is intended to
be either representative of the kind of computation the
program is intended to perform, or sufficiently varied in
order to "fool" some of the more performing processors
that gain their speed using sophisticated caching and/or
pipelining processes. In the example given below, we move
data between two arbitrarily large arrays, that are
allocated and de-allocated during each call of the
"representative code" routine. Furthermore, the direction
of the data movement is dependent of a random value;
however, you will notice that the alternate execution
paths are strictly equivalent, so to be able to cope with
any eventual random number generator bias.
ôτΦ≥ ±ε⌠≤ΦφΣ Φ≥ Φφ≤ΣφπΣπ ≤ε ßΣ ⌠≥Σπ ß√ αφ√εφΣ Φφ αφ√ δαφµ⌠αµΣ;
the example given below is given in Borland Turbo Pascal 6.0,
but can be easily adapted and translated into any other popular
language.
ôτΣ ΓεπΣ ßΣδε÷ Φ≥ ΦφΓδ⌠πΣπ Φφ ≤τΣ σΦδΣ ôêîä.ÅÇÆ
(*****************************************************************)
(* TIME unit - for the determination of true system speed. *)
(* *)
(* This unit returns a value proportional to the speed of the *)
(* CPU of the computer it is running on. *)
(* *)
(* Written in Borland Turbo Pascal version 6.0 *)
(* By Marc Dufour, September 18, 1993 *)
(*****************************************************************)
unit time;
interface
function speed_index: longint;
(*****************************************************************)
(* That's it. One tiny function that returns the value gathered *)
(* during the unit's initialization (automatically called when *)
(* the "time" unit is referenced for the first time. *)
(* Oh, what? Why a function? Well, it's to keep the unit as *)
(* it should be, a one-way provider of information, so to insure *)
(* that the value is not clobbered by careless programming, and *)
(* to adhere to the canons of clean, simple and structured *)
(* programming. *)
(*****************************************************************)
implementation
uses dos;
var TimeCount: longint;
(*****************************************************************)
(* This is the function that is called to gain acces to the *)
(* variable "TimeCount", that is kept securely within the body *)
(* of the "time" unit to insure it's strict output-only role. *)
(*****************************************************************)
function speed_index: longint;
begin
speed_index:=TimeCount;
end; {speed_index}
(*****************************************************************)
(* This function returns the number of seconds since midnight. *)
(*****************************************************************)
function time_of_day: longint;
var Hour,
Minute,
Second,
Sec100: Word;
begin
dos.GetTime(Hour, Minute, Second, Sec100);
time_of_day:=hour*3600+minute*60+second;
end; {time_of_day}
(*****************************************************************)
(* This procedure emulates the kind of processing the system is *)
(* supposed to perform during the execution of the program. Some *)
(* fast processors optimize the code that is executed or the *)
(* position of the data, so we try to be as generous as possible *)
(* in generating differing processing possibilites, as to insure *)
(* that the calculations done reflect as accurately as possible *)
(* the true speed of the processor. You may want to exercise *)
(* your imagination there... *)
(* *)
(* A word of caution, though. If you want a greater resolution, *)
(* you will find preferable a routine that executes quickly. *)
(* For example, I get a result of about 2300 on a 40mhz 80386DX *)
(* and running under Windows. Your mileage may vary... *)
(*****************************************************************)
procedure Representative_computations;
const Biggy_Size=2048;
type biggy= array[1..Biggy_size] of byte;
var b1, b2: ^biggy; {b1 and b2 are pointers to the big array.}
begin
new(b1); {here, we allocate memory for the big arrays}
new(b2);
if random(10)>5
then b2^:=b1^ {here, we move the DATA from one big array to}
else b1^:=b2^; {the other instead of only the pointer reference}
dispose(b2); {and we nicely clean-up after ourselves,}
dispose(b1); {by nicely giving-up the memory we used.}
end; {Representative_computations}
(*****************************************************************)
(* This is the unit's initialization, where the computation for *)
(* determining the system speed is done. *)
(*****************************************************************)
var timer: longint;
begin
timer:=Time_of_day;
repeat
until timer<>Time_of_day;
Timer:=Time_of_day;
TimeCount:=0;
repeat
inc(TimeCount);
Representative_computations;
until Timer<>Time_of_day;
end.
(******************************************************)
(* Now, here is the main program that uses the stuff. *)
(******************************************************)
program test_time;
uses time;
begin
writeln('Machine speed=',time.speed_index);
end. ñ